package disjunction.examples.mvc
{
	import disjunction.Controller;

	import flash.display.DisplayObjectContainer;
	
	/**
	 * Basics Example main controller update strategy.
	 * 
	 * @author Nick Wiggill
	 */
	
	public class DemoController extends Controller
	{
		public override function initialise(data:Object):void
		{			
			view.start();
		}
		
		protected override function update(timeDeltaMs:uint):void
		{
			//apply motion in pixels per second
			model.position.x += model.motion.x * timeDeltaMs/1000; 
			model.position.y += model.motion.y * timeDeltaMs/1000;
			
			//bounce if edge hit
			var context:DisplayObjectContainer = view.context as DisplayObjectContainer;

			if (model.position.x < model.radius ||
				model.position.x > context.stage.stageWidth - model.radius)
				reverseMotionInX();
					
			if (model.position.y < model.radius ||
				model.position.y > context.stage.stageHeight - model.radius)
				reverseMotionInY();
			
		}

		public function reverseMotionInX():void
		{
			model.motion.x *= -1;
		}
		public function reverseMotionInY():void
		{
			model.motion.y *= -1;
		}
	}
}